import { lazy } from "react";
import type { RouteObject } from "react-router-dom";
import { Navigate } from "react-router-dom";

// 组件列表
const Login = lazy(() => import("@/pages/login/index"));
const Layout = lazy(() => import("@/layouts/index"));
const Home = lazy(() => import("@/pages/home/index"));
const Personal = lazy(() => import("@/pages/personal/index"));
const Error404 = lazy(() => import("@/components/Error/404"));

// 路由列表
const defaultRoutes: RouteObject[] = [
  {
    path: "/login",
    element: <Login />
  },
  {
    path: "/",
    element: <Layout />,
    children: [
      {
        index: true,
        element: <Navigate to="/home" replace />
      },
      {
        path: "/home",
        element: <Home />
      },
      // 个人中心板块的页面
      {
        path: "/personal",
        element: <Personal />
      }
      // 权限路由【如果不需要权限，路由全部加在此即可】
    ]
  },
  // 通配符捕获未知路由，渲染404
  {
    path: "*",
    element: <Error404 />
  }
];

// 如不需要权限，直接在这里导出全部路由
// const router = createBrowserRouter(defaultRoutes);
// export default router;
export default defaultRoutes;
